package com.bawei.demo_shoppingcar.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

import com.bawei.demo_shoppingcar.bean.ShoppingDataBean;
import com.bawei.demo_shoppingcar.interfac.UpdateShopping;
import com.google.gson.Gson;

import java.util.ArrayList;

/**
 * Created by HP on 2017/3/16.
 */

public class HomeAsyncTask extends AsyncTask<String, Void, ShoppingDataBean> {


    private ProgressDialog dialog;
    Context context;
    ArrayList<String> list = new ArrayList<>();
    private String json;
    UpdateShopping updateShopping;

    public HomeAsyncTask(Context context, UpdateShopping updateShopping) {
        this.context = context;
        this.updateShopping = updateShopping;
    }

    @Override
    protected void onPreExecute() {
        dialog = new ProgressDialog(context);
        dialog.setMessage("正在加载,请稍后...");
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }

    @Override
    protected void onPostExecute(ShoppingDataBean dataBean) {
        dialog.dismiss();
        updateShopping.getHaderImageURL(dataBean);
    }

    @Override
    protected ShoppingDataBean doInBackground(String... params) {

        String json = HttpUtils.readUrl(params[0]);
        Gson gson = new Gson();
        ShoppingDataBean shoppingDataBean = gson.fromJson(json, ShoppingDataBean.class);

        return shoppingDataBean;
    }

}
